package com.itita.ww2.utils;

import java.security.SecureRandom;

import org.apache.commons.codec.binary.Base64;

public class MathUtil {
	// private static final Logger logger = LoggerFactory.getLogger(MathUtil.class);
	private static SecureRandom secureRandom = new SecureRandom();

	/**
	 * 获取数组中的最大值
	 */
	public static final int max(int[] arguments) {
		int maxValue = Integer.MIN_VALUE;
		for (int i = 0; i < arguments.length; ++i) {
			if (arguments[i] > maxValue) {
				maxValue = arguments[i];
			}
		}
		return maxValue;
	}

	/**
	 * 生成Salt值(强随机算法)
	 */
	public static final String GenerateSalt() {
		byte[] salt = new byte[0x4];
		secureRandom.nextBytes(salt);
		return Base64.encodeBase64String(salt);
	}

	/**
	 * 生成随机的int(给定范围)
	 */
	public static final int RandomInt(int min, int max) {
		int ret = secureRandom.nextInt(max - min + 1) + min;
		return ret;
	}

}
